<template>
	<view class="pb">
		<view class="text-center p15">
			<uni-row :gutter="12">
				<uni-col :span="8">
					<uni-icons @click="onSet" color="#2979ff" type="gear-filled" size="30"></uni-icons>
					<view >设置</view>
				</uni-col>
				<uni-col :span="8">
					<uni-icons @click="onEntrust" color="#e43d33" type="contact-filled" size="30"></uni-icons>
					<view >委托</view>
				</uni-col>
				<uni-col :span="8">
					<uni-icons @click="onPreview" color="#18bc37" type="map" size="30"></uni-icons>
					<view >预览</view>
				</uni-col>
			</uni-row>
		</view>
		<view class="line_ccc"></view>
		<view class="text-center mt20"><image class="head_img" :src="infoData.baseInfo.head_img ? infoData.baseInfo.head_img : 'https://xinzhu-1301398555.cos.ap-shanghai.myqcloud.com/wxapp/avatar.png'" mode="widthFix"></image><uni-tag :inverted="true" class="ml5" text="编辑" type="warning" size="mini" @click="onEditUserinfo(0)" /></view>
		<view class="p0-15">
			<uni-title type="h2" :title="infoData.baseInfo.name"></uni-title>
			<view class="user-info">{{infoData.baseInfo.sex == 1 ? '男' : '女'}} | {{infoData.baseInfo.area}}</view>
		</view>
		<uni-section :title="'电话：'+infoData.baseInfo.mobilephone">
			<template v-slot:decoration>
				<view class="decoration"></view>
			</template>
		</uni-section>
		<uni-section :title="'邮箱：'+infoData.baseInfo.email">
			<template v-slot:decoration>
				<view class="decoration"></view>
			</template>
		</uni-section>
		
		
		<view class="view-line"></view>
		<uni-section title="求职意向">
			<template v-slot:decoration>
				<view class="decoration"></view>
			</template>
			<template v-slot:right>
				<uni-tag :inverted="true" text="编辑" type="warning" size="mini" @click="onEditIntention(0)" />
			</template>
		</uni-section>
		<view class="p0-15-15-15">
			<view class="mt5">职位：{{infoData.workExpect.position ? infoData.workExpect.position : ''}}</view>
			<view class="mt5">薪资：{{infoData.workExpect.salary ? infoData.workExpect.salary : ''}}/{{infoData.workExpect.salary_type ? infoData.workExpect.salary_type : ''}}</view>
		</view>
		
		<view class="p0-15-15-15 text-center fz08rem" v-if="!infoData.workExpect.position">
			<view class="mt10"><text>尚未填写</text></view>
			<view class="mt10"><uni-tag text="立即完善" type="warning" @click="onEditIntention(0)" /></view>
			<view class="mt10 fz07rem"><text>请根据实际情况填写</text></view>
		</view>
		
		
		<view class="view-line"></view>
		<uni-section title="工作经验">
			<template v-slot:decoration>
				<view class="decoration"></view>
			</template>
			<template v-slot:right>
				<uni-tag :inverted="true" text="新增" type="warning" size="mini" @click="onEditWork(0)" />
			</template>
		</uni-section>
		<view class="p0-15-15-15" v-for="item in infoData.WorkList" :key="item.id">
			<view class="title">{{item.ccompname}}
				<uni-tag :inverted="true" class="ml5" text="编辑" type="warning" size="mini" @click="onEditWork(1,item)" />
			</view>
			<view class="fz09rem">{{item.timefrom}} - {{item.timeto}}</view>
			<uni-title type="h3" :title="item.cposition"></uni-title>
			<view class="mt5">行业：{{item.workindustry}}</view>
			<view class="mt5">描述：{{item.cworkdescribe}}</view>
			<view class="mt5">业绩：{{item.performance}}</view>
		</view>
		
		<view class="p0-15-15-15 text-center fz08rem" v-if="infoData.WorkList.length == 0">
			<view class="mt10"><text>尚未填写</text></view>
			<view class="mt10"><uni-tag text="立即完善" type="warning" @click="onEditWork(0)" /></view>
			<view class="mt10 fz07rem"><text>请根据实际情况填写</text></view>
		</view>
		
		
		
		<view class="view-line"></view>
		<uni-section title="项目经验">
			<template v-slot:decoration>
				<view class="decoration"></view>
			</template>
			<template v-slot:right>
				<uni-tag :inverted="true" text="新增" type="warning" size="mini" @click="onEditProject(0)" />
			</template>
		</uni-section>
		<view class="p0-15-15-15" v-for="item in infoData.project" :key="item.id">
			<view class="title">{{item.cprojectname}}
				<uni-tag :inverted="true" class="ml5" text="编辑" type="warning" size="mini" @click="onEditProject(1,item)" />
			</view>
			<view class="fz09rem">{{item.starttime}} - {{item.endtime}}</view>
			<view class="mt5">{{item.post}}{{item.costs}}</view>
			<view class="mt5">公司：{{item.ccompname}}</view>
			<view class="mt5">描述：{{item.cdescribe}}</view>
		</view>
		
		<view class="p0-15-15-15 text-center fz08rem" v-if="infoData.project.length == 0">
			<view class="mt10"><text>尚未填写</text></view>
			<view class="mt10"><uni-tag text="立即完善" type="warning" @click="onEditProject(0)" /></view>
			<view class="mt10 fz07rem"><text>请根据实际情况填写</text></view>
		</view>
		
		<view class="view-line"></view>
		<uni-section title="教育经历">
			<template v-slot:decoration>
				<view class="decoration"></view>
			</template>
			<template v-slot:right>
				<uni-tag :inverted="true" text="新增" type="warning" size="mini" @click="onEditEducation(0)" />
			</template>
		</uni-section>
		<view class="p0-15-15-15" v-for="item in infoData.education" :key="item.id">
			<view class="title">{{item.cschoolname}}
				<uni-tag :inverted="true" class="ml5" text="编辑" type="warning" size="mini" @click="onEditEducation(1,item)" />
			</view>
			<view class="fz09rem">{{item.timefrom}} - {{item.timeto}}</view>
			<view class="mt5">专业：{{item.cmajordes}}</view>
			<view class="mt5">描述：{{item.cdescribe}}</view>
		</view>
		
		<view class="p0-15-15-15 text-center fz08rem" v-if="infoData.education.length == 0">
			<view class="mt10"><text>尚未填写</text></view>
			<view class="mt10"><uni-tag text="立即完善" type="warning" @click="onEditEducation(0)" /></view>
			<view class="mt10 fz07rem"><text>请根据实际情况填写</text></view>
		</view>
		
		<view class="view-line"></view>
		<uni-section title="培训经历">
			<template v-slot:decoration>
				<view class="decoration"></view>
			</template>
			<template v-slot:right>
				<uni-tag :inverted="true" text="新增" type="warning" size="mini" @click="onEditTrain(0)" />
			</template>
		</uni-section>
		<view class="p0-15-15-15" v-for="item in infoData.skillTrain" :key="item.id">
			<view class="title">{{item.ctrainname}}
				<uni-tag :inverted="true" class="ml5" text="编辑" type="warning" size="mini" @click="onEditTrain(1,item)" />
			</view>
			<view class="fz09rem">{{item.timefrom}} - {{item.timeto}}</view>
			<view class="mt5">专业：{{item.ctrainlesson}};地区：{{item.ctrainplace}}</view>
			<view class="mt5 fz07rem">描述：{{item.cdescribe}}</view>
		</view>
		
		<view class="p0-15-15-15 text-center fz08rem" v-if="infoData.skillTrain.length == 0">
			<view class="mt10"><text>尚未填写</text></view>
			<view class="mt10"><uni-tag text="立即完善" type="warning" @click="onEditTrain(0)" /></view>
			<view class="mt10 fz07rem"><text>请根据实际情况填写</text></view>
		</view>
		
		<view class="view-line"></view>
		<uni-section title="证书">
			<template v-slot:decoration>
				<view class="decoration"></view>
			</template>
			<template v-slot:right>
				<uni-tag :inverted="true" text="新增" type="warning" size="mini" @click="onEditCert(0)" />
			</template>
		</uni-section>
		<view class="p0-15-15-15" v-for="item in infoData.cert" :key="item.id">
			<view class="title">{{item.certname}}
				<uni-tag :inverted="true" class="ml5" text="编辑" type="warning" size="mini" @click="onEditCert(1,item)" />
			</view>
			<view class="fz09rem">{{item.getdate}}</view>
			<view class="mt5">成绩：{{item.score}}</view>
		</view>
		
		<view class="p0-15-15-15 text-center fz08rem" v-if="infoData.cert.length == 0">
			<view class="mt10"><text>尚未填写</text></view>
			<view class="mt10"><uni-tag text="立即完善" type="warning" @click="onEditCert(0)" /></view>
			<view class="mt10 fz07rem"><text>请根据实际情况填写</text></view>
		</view>
		
		
		<uni-popup ref="popup" background-color="#fff">
			<view class="p15 overflow-y">
				<uni-row class="p8">
					<uni-col :span="12">
						<uni-section title="权限设置" type="line">
							<view class="p8">
								<uni-data-checkbox @change="changeOpen" v-model="is_open" :localdata="open"></uni-data-checkbox>
							</view>
						</uni-section>
					</uni-col>
					<uni-col :span="12">
						<uni-section title="操作" type="line">
							<view class="p8">
								<uni-tag :inverted="true" class="ml5" text="删除简历" @click="onDelete()" />
							</view>
						</uni-section>
					</uni-col>
				</uni-row>
				
				
			</view>
		</uni-popup>
		
		<uni-popup ref="entrust" type="dialog">
			<uni-popup-dialog type="success" cancelText="取消" confirmText="确定" title="委托找工作确认" content="委托后,平台将把您的简历信息提供给合作方企业" @confirm="confirmEntrust"></uni-popup-dialog>
		</uni-popup>
		
		<uni-popup ref="delete" type="dialog">
			<uni-popup-dialog type="success" cancelText="取消" confirmText="确定" title="提示" content="删除简历后无法撤销,确定删除么" @confirm="confirmDelete"></uni-popup-dialog>
		</uni-popup>
		
		<uni-popup ref="insert" type="dialog">
			<uni-popup-dialog type="success" cancelText="取消" confirmText="去创建" title="提示" content="暂无简历,立即去创建？" @confirm="confirmInsert"></uni-popup-dialog>
		</uni-popup>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				resume_id:0,
				uid:0,
				is_action_Work:false,
				WorkId:0,
				is_action_Userinfo:false,
				is_action_Train:false,
				is_action_Project:false,
				is_action_Education:false,
				is_action_Cert:false,
				infoData:{
					WorkList: [],
					attach: [],
					baseInfo: {name:'姓名',age:22,area:'地区',mobilephone:'未填写',email:'未填写',head_img:'https://xinzhu-1301398555.cos.ap-shanghai.myqcloud.com/wxapp/avatar.png'},
					cert: [],
					education: [],
					evaluate: "",
					phone_list: [],
					project: [],
					score: 3,
					skillTrain: [],
					skilllanguage: [],
					workExpect: {},
				},
				
				is_open:0,
				open:[{text: '对所有人公开',value: 0}, {text: '完全保密',value: 1}],
				
				shareinfo:{title:'',img:'',path:''}
			}
		},
		onShow() {
			// api/updCV
			// hidden: 1
			
			// api/entrustCV
			// api/readCV	
			this.onGetData()
		},
		methods: {
			onGetData(){
				let _this = this
				this.$request('/api/listCV','POST',{}).then(res => {
					if(!res.data.length){
						this.$refs.insert.open('center')
						return
					}else{
						_this.resume_id = res.data[0].id
						_this.uid = res.data[0].uid
						_this.is_open = res.data[0].hidden
						_this.onGetInfo()
					}
					
				}).catch(err => {
					console.log(err)
				})
			},
			onGetInfo(id){
				let _this = this
				this.$request('/api/readCV','POST',{resume_id:this.resume_id}).then(res => {
					_this.infoData = res.data
					if(_this.infoData.workExpect){
						_this.infoData.workExpect.salary = _this.infoData.workExpect.salary_type == 2 ? _this.$func.month_wages[_this.infoData.workExpect.salary] : _this.$func.year_wages[_this.infoData.workExpect.salary]
						_this.infoData.workExpect.salary_type = _this.infoData.workExpect.salary_type == 2 ? '月' : '年'
					}
					
					_this.shareinfo.title = _this.infoData.baseInfo.name+'的简历'
					_this.shareinfo.img = _this.infoData.baseInfo.head_img
					_this.shareinfo.path = '/pages/resume/resume?user_id='+_this.uid+'&resume_id='+_this.resume_id
				}).catch(err => {
					console.log(err)
				})
			},
			onSet(){
				if(!this.resume_id){
					uni.showToast({title: '请先编写简历',icon: 'error',duration: 2000})
					return;
				}
				this.$refs.popup.open('bottom')
			},
			confirmInsert(){
				let _this = this
				this.$request('/api/addCV','POST',{resume_id:this.resume_id}).then(res => {
					_this.onEditUserinfo(0)
				}).catch(err => {
					console.log(err)
				})
			},
			changeOpen(e){
				let _this = this
				this.$request('/api/updCV','POST',{hidden:e.detail.value,id:this.resume_id}).then(res => {
					if(res.code == 0){
						uni.showToast({title: '操作成功',icon: 'success',duration: 2000})
					}
				}).catch(err => {
					
				})
			},
			onDelete(){
				this.$refs.delete.open('center')
			},
			confirmDelete(){
				let _this = this
				this.$request('/api/delCV','POST',{id:_this.resume_id}).then(res => {
					_this.onGetData(0)
					if(res.code == 0){
						_this.$refs.popup.close()
						uni.showToast({title: '操作成功',icon: 'success',duration: 2000})
					}
				}).catch(err => {
					
				})
			},
			onEntrust(){
				if(!this.resume_id){
					uni.showToast({title: '请先编写简历',icon: 'error',duration: 2000})
					return;
				}
				this.$refs.entrust.open('center')
			},
			confirmEntrust(){
				let _this = this
				this.$request('/api/entrustCV','POST',{}).then(res => {
					if(res.code == 0){
						uni.showToast({title: '操作成功',icon: 'success',duration: 2000})
					}
				}).catch(err => {
					console.log(err)
				})
			},
			onPreview(){
				if(!this.resume_id){
					uni.showToast({title: '请先编写简历',icon: 'error',duration: 2000})
					return;
				}
				uni.navigateTo({
					url: "/user/resume/preview?user_id="+this.uid+"&resume_id="+this.resume_id
				});
			},
			onEditIntention(){
				this.onLink('/user/resume/resume_intention',0)
			},
			onEditWork(type,data){
				if(type == 0){
					this.onLink('/user/resume/resume_work',0)
					return
				}
				this.onLink('/user/resume/resume_work',data.id)
			},
			onEditProject(type,data){
				if(type == 0){
					this.onLink('/user/resume/resume_project',0)
					return
				}
				this.onLink('/user/resume/resume_project',data.id)
			},
			onEditEducation(type,data){
				if(type == 0){
					this.onLink('/user/resume/resume_education',0)
					return
				}
				this.onLink('/user/resume/resume_education',data.id)
			},
			onEditTrain(type,data){
				if(type == 0){
					this.onLink('/user/resume/resume_train',0)
					return
				}
				this.onLink('/user/resume/resume_train',data.id)
			},
			onEditCert(type,data){
				if(type == 0){
					this.onLink('/user/resume/resume_cert',0)
					return
				}
				this.onLink('/user/resume/resume_cert',data.id)
			},
			onEditUserinfo(type,data){
				if(type == 0){
					this.onLink('/user/resume/resume_userinfo',0)
					return
				}
				this.onLink('/user/resume/resume_userinfo',data.id)
			},
			onLink(url,id){
				uni.navigateTo({
					url: url+"?id="+id+"&resume_id="+this.resume_id
				});
			}
		}
	}
</script>

<style>
.overflow-y{height: 140px;}
.title{font-size: 1.2rem;font-weight: 600;}
.head_img{width: 120px;height: 120px;}
.user-info{margin-top: 5px;font-size: .9rem;color: #666;}
.title{line-height: 40px;}

.fz07rem{color: #666;}
</style>
